package com.woniuxy.Listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @auther linke
 * @create 2021-10-25 11:19
 * 监听器功能实现
 */
@WebListener
public class MyServletContextListener implements ServletContextListener {
    /**
     *
     * @param sce
     *
     * 监听不同的对象，监听的范围跟对象的生命周期相关
     * ServletContextListener
     * 服务器开启时
     * 执行监听方法
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("contextInitialized监听器启动...MyServletContextListener");

        //获取对象，获取参数
        ServletContext servletContext = sce.getServletContext();
        String name = servletContext.getInitParameter("name");
        System.out.println(name);

    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("contextDestroyed监听器销毁...MyServletContextListener");
    }
}
